import { request, auth_request } from "@/utils/service"
import { getIdToken, getToken } from "@/utils/cache/cookies"
;``
export interface ILoginData {
  /** admin 或 editor */
  username: "admin" | "editor"
  /** 密码 */
  password: string
  /** 验证码 */
  code: string
}
export interface IAccessTokenReq {
  code: string
  grant_type: "authorization_code"
  redirect_uri: string
  client_id: "6edb7778-821b-4ce3-a660-dce9c8e4eecc"
}

export interface IAccessToken {
  access_token: string
  expires_in: number
  id_token: string
  refresh_token: string
  scope: string
  token_type: string
}

/** 获取登录验证码 */
export function getLoginCodeApi() {
  return request({
    url: "login/code",
    method: "get"
  })
}
/** 登录并返回 Token */
export function loginApi(data: ILoginData) {
  return request({
    url: "/login",
    method: "post",
    data
  })
}
/** 获取用户详情 */
// export function getUserInfoApi() {
//   return request({
//     url: "/userinfo",
//     method: "get",
//     baseURL: import.meta.env.VITE_AUTH_CENTER_BASE_API,
//     headers: {
//       // 携带 Token
//       Authorization: "Bearer " + getToken()
//     }
//   })
// }
export function getUserInfoApi() {
  return request({
    url: "/userinfo",
    method: "get",
    // baseURL: import.meta.env.VITE_AUTH_CENTER_BASE_API,
    headers: {
      // 携带 Token
      // Authorization: "Bearer " + getToken()
    }
  })
}

export function getAccessToken(req: IAccessTokenReq) {
  return auth_request({
    url: "/oauth2/token",
    method: "post",
    data: req
  })
}

export function notifyAuthCenterLogoutApi() {
  return request({
    url: "/logout",
    method: "post"
  })
}
